package com.itheima.dao;

import com.itheima.pojo.Tag;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface TagMapper extends Mapper<Tag> {

    @Select("SELECT t_tag.* FROM t_tag where uid in (SELECT tag_uid from t_blog_tag where blog_uid=#{uid}) ")
    @Results({
            @Result(column = "uid", property = "uid"),
            @Result(column = "content", property = "content"),
            @Result(column = "status", property = "status"),
            @Result(column = "click_count", property = "clickCount"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "sort", property = "sort"),
    })
    List<Tag> findTags(@Param("uid") String uid);

    @Select("select max(sort) from t_tag")
    Long getSortMax();

    @Select("SELECT t.uid,count(t.uid) count FROM t_tag t LEFT JOIN t_blog b on b.tag_uid = t.uid GROUP BY t.uid ORDER BY count(t.uid) DESC")
    List<Map<String, Object>> tagSortByCite();
}
